package com.NetWork.Encoder;


import com.Gameplay.character.Role.parentRole;
import com.NetWork.PlayerStatus.PlayerStatus;
import com.core.Window.Main.Game;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;


public class PlayerEncoder extends MessageToByteEncoder<parentRole> {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, parentRole parentRole, ByteBuf byteBuf) throws Exception {
        PlayerStatus playerStatus = new PlayerStatus(parentRole.getId(), parentRole.getCurrentX(),
                parentRole.getCurrentY(), parentRole.getHealth(),
                parentRole.getEnergy(), parentRole.getPushCurrentX(),
                parentRole.getDamage(),parentRole.isIsblocking());
        playerStatus.setClientId(Game.ClientID);


        String json = JsonEncoder.pojoToJson(playerStatus);
        channelHandlerContext.writeAndFlush(json+"\n");
    }
}
